Next | Prev | Up | Top | Contents | Index
Entry Point close()
The kernel calls the pfxclose() entry when the last process calls close() or umount() for the device special file. It is important to know that when the device can be opened by multiple processes, pfxclose() is not called for every close() function, but only when the last remaining process closes the device and no other processes have it open.
The function prototype and arguments of pfxclose() are
int pfxclose(dev_t dev, int flag, int otyp, cred_t *crp);
The arguments are the same as were passed to pfxopen(). However, the flag argument is not necessarily the same as at any particular call to open().
It is up to you to design the meaning of "close" for this type of device:
- If the device is opened and closed frequently, you may decide to retain dynamic data structures.
- If the device can perform an action such as "rewind" or "eject," you decide whether that action should be done upon close. Possibly the choice of acting or not acting can be set by an ioctl() call; or possibly the choice can be encoded into the device minor number--for example, the no-rewind-on-close option is encoded in certain tape minor device numbers.
- If the pfxopen() entry point supports exclusive access, and it can be waiting for the device to be free, pfxclose() must release the wait.
The pfxclose() entry can detect an error and report it with a return code. However, the file is closed or unmounted regardless.
Next | Prev | Up | Top | Contents | Index